package com.jxb.commentree.controller;

import com.jxb.commentree.dto.CommentDto;
import com.jxb.commentree.service.CommentOnService;
import io.swagger.annotations.Api;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value="/api")
@Api(value="博客相关接口")
public class CommentOnController {
    @Resource
    private CommentOnService commentOnService;

    @CrossOrigin(origins = "*")
    @GetMapping(value = "/blog/comment/{blogId}")
    public ResponseEntity<List<CommentDto>> getBlogById(@PathVariable("blogId") Integer blogId){
        return ResponseEntity.ok(commentOnService.getAllCommentByBlogId(blogId));
    }

    @CrossOrigin(origins = "*")
    @PostMapping(value = "/blog/comment")
    public void addComment(@RequestBody CommentDto commentDto){
        commentOnService.addComment(commentDto);
    }

}
